package com.wanxin.wb.module.test;



import java.io.UnsupportedEncodingException;
import sun.misc.*;

public class MyBase64 {
	// 加密
	public static String getBase64(String str) {
		byte[] b = null;
		String s = null;
		try {
			b = str.getBytes("utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		if (b != null) {
			s = new BASE64Encoder().encode(b);
		}
		return s;
	}

	// 解密
	public static String getFromBase64(String s) {
		byte[] b = null;
		String result = null;
		if (s != null) {
			BASE64Decoder decoder = new BASE64Decoder();
			try {
				b = decoder.decodeBuffer(s);
				result = new String(b, "utf-8");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public static void main(String[] args) {
		String s = "eyJjYXJkRmxhZyI6IjEiLCJjYXJkTGlzdCI6IldGMUFqeThqVXdEdXhMZUJHa2I0TVhadzgxS1BINFZRbVg4K0JRMG9DQm9yd0x2d3VGUVdoVG5tZjljK3Brc3k4KzVXa2VuZmFWYUdRRkVNelhaWWhSUmd6TVJvYXI2bmJaK0dUVXE0SWNjTW5OUTh5TzRIdHJza3JQVGtLNjhkYkhJbUtMQjlNNHg4djNVd1JGWENGS09VUVZQRG9vSTdzZkxwTlI1UVRHSS9hYW5PeVhYVkZubUFUSFRJcUNkL0tYMXQzUzA0dTV0djBzYjNoUTNDamM2R3hVMnFLYzNPT1Rzb282elZwUWpIdFNGeUxmOHV4c3hNZ0Z6TTAxbmhRL1c0ajRSeCtmYVVrNWRjLy85M1Z2YmJ1TVRMQWRWNmVMUTFZQmRBbUovVU5sMmRZb0UyZTVLOU0xcnluakJKMTh1SjRtYWZienN3b09yK21VRWd6UT09IiwiZW1haWwiOiIiLCJlbmNDZXJ0SWQiOiIwIiwiZmlyc3ROYW1lIjoic2FuZyIsImluc0NvZGUiOiIxMjM0NTY3OCIsImxhbmd1YWdlIjoiemgtY24iLCJsYXN0TmFtZSI6InpoYW5nIiwibW9iaWxlIjoiKzg2LTEzNTExMTEyMjIyIiwicG10Q29kZSI6IjIwMTYwNDI4MDAwMiIsInByb2NEdCI6IjIwMTYwNDI4MTU1NDU1IiwicHJvY1R5cGUiOiIxIiwicmFuZG9tTnVtIjoiMTIzNDU2NzgiLCJyZXN2RmxkIjoiNzEwNTg0MDAwMDAxIiwic2lnbkNlcnRJZCI6IjAifQ==";
		System.out.println(getFromBase64(s));
	}
}
